<template>
    <div>
        <el-form ref="form" id="printContent" :model="form" :rules="rules" label-width="100px" style="text-align:center;padding:4%">
            <el-form-item label="经济舱票价" prop="touristClassPrice">
                <el-input v-model="form.touristClassPrice"></el-input>
            </el-form-item>
            <el-form-item label="商务舱票价" prop="businessClassPrice">
                <el-input v-model="form.businessClassPrice"></el-input>
            </el-form-item>
            <el-form-item label="头等舱票价" prop="firstClassPrice">
                <el-input v-model="form.firstClassPrice"></el-input>
            </el-form-item>
            <el-form-item label="上浮范围" prop="floatingRange">
                <el-input v-model="form.floatingRange"></el-input>
            </el-form-item>
            <el-form-item label="下浮范围" prop="decreaseRange">
                <el-input v-model="form.decreaseRange"></el-input>
            </el-form-item>
        </el-form>
        <div style="text-align:center">
            <el-button type="primary" @click="saveFare" :disabled="disable">保存信息</el-button>
            <el-button type="warning" v-print="'#printContent'">打印表格</el-button>
        </div>
    </div>
</template>
<script>
export default {
    name:'fare',
    data(){
        return{
            form:{},
            rules:{
                touristClassPrice:[
                    { required: true, message: '请输入经济舱票价', trigger: 'blur' }
                ],
                businessClassPrice:[
                    { required: true, message: '请输入商务舱票价', trigger: 'blur' }
                ],
                firstClassPrice:[
                    { required: true, message: '请输入头等舱票价', trigger: 'blur' }
                ],
                floatingRange:[
                    { required: true, message: '请输入上浮范围', trigger: 'blur' }
                ],
                decreaseRange:[
                    { required: true, message: '请输入下浮范围', trigger: 'blur' }
                ]
            }
        }
    },
    methods:{
        getFare(){
            console.log(this.form)
            this.$http.get("/api/fare/getFare").then((res)=>{
                console.log(res);
                this.form = res.data
            })
        },
        saveFare(){
            console.log(this.form)
            this.$http.post("/api/fare/editFare",this.form).then((res)=>{
                if(res.status == 200){
                    this.$message({
                        type: 'success',
                        message: '修改成功!'
                    });
                }
            })
        }
    },
    mounted(){
        this.getFare();
    },
    computed:{
        disable(){
            let admin = this.$cookies.get("admin")
            return admin.admin_type !== 0;
        }
    }
}
</script>